package com.hangxiang.approval.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hangxiang.approval.common.CcPersonInsertCommon;
import com.hangxiang.approval.common.CcPersonUpdateCommon;
import com.hangxiang.approval.common.IntegerCommon;
import com.hangxiang.approval.dao.CcPersonDao;
import com.hangxiang.approval.entity.CcPerson;
import com.hangxiang.approval.service.CcPersonService;
import com.hangxiang.approval.vo.CcPersonVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * (CcPerson)表服务实现类
 *
 * @author makejava
 * @since 2020-11-24 15:03:55
 */
@Service("ccPersonService")
public class CcPersonServiceImpl extends ServiceImpl<CcPersonDao, CcPerson> implements CcPersonService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private CcPersonDao ccPersonDao;

    /**
     * 通过ID查询单条数据
     *
     * @param common 主键
     * @return 实例对象
     */
    @Override
    public CcPersonVo queryById(IntegerCommon common) {
        CcPersonVo vo = new CcPersonVo();
        CcPerson ccPerson = ccPersonDao.selectById(common.getValue());
        BeanUtils.copyProperties(ccPerson, vo);
        return vo;
    }


    /**
     * 新增数据
     *
     * @param ccPersonInsertCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer insertCcPerson(CcPersonInsertCommon ccPersonInsertCommon) {
        CcPerson ccPerson = new CcPerson();
        BeanUtils.copyProperties(ccPersonInsertCommon, ccPerson);
        ccPersonDao.insert(ccPerson);
        return ccPerson.getCcPersonId();
    }

    /**
     * 修改数据
     *
     * @param ccPersonUpdateCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer updateCcPerson(CcPersonUpdateCommon ccPersonUpdateCommon) {
        CcPerson ccPerson = new CcPerson();
        BeanUtils.copyProperties(ccPersonUpdateCommon, ccPerson);
        ccPersonDao.updateById(ccPerson);
        return ccPerson.getCcPersonId();
    }
}